package com.ruoyi.lc.model;

import java.time.LocalDateTime;
import java.util.Map;

import com.ruoyi.common.constant.SystemConst;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.lc.enums.LcModelState;

import lombok.Data;

@Data
public class BaseModel {
	
	private Long id;
	
	private String masterTableName;
	
	private LcModelState modelState;
	
	private Map<String, Object> masterData;
	
	
	public BaseModel(String masterTableName) {
		this.masterTableName = masterTableName;
	}
	
	public boolean save() {
		if(this.id == null) {
			initAddMasterValue();
		} else {
			initEditMasterValue();
		}
		if(beforeSave()) {
			//执行保存操作
		}
		afterSave();
		return true;
	}
	
	public boolean beforeSave() {
		return true;
	}
	
	public void afterSave() {
		
	}
	
	
	/**
	 * 新增时初始化数据
	 */
	public void initAddMasterValue() {
		masterData.put(SystemConst.O_CREATE_TIME, LocalDateTime.now());
		masterData.put(SystemConst.O_CREATE_BY, SecurityUtils.getUsername());
		masterData.put(SystemConst.O_USER_ID, SecurityUtils.getUserId());
		masterData.put(SystemConst.O_DEPT_ID, SecurityUtils.getDeptId());
	}
	
	
	public void initEditMasterValue() {
		masterData.put(SystemConst.O_UPDATE_BY, SecurityUtils.getUsername());
		masterData.put(SystemConst.O_UPDATE_TIME, LocalDateTime.now());
	}

}
